package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description NursingProjectServiceImpl
 * @Author lgj
 * @Date 2025-08-28
 */
@Service
public class NursingProjectServiceImpl implements NursingProjectService {
    @Autowired
    private NursingProjectMapper nursingProjectMapper;
    @Override
    public PageResponse<NursingProjectVo> getByPage(String name, Integer stauts, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingProjectVo> nursingProjectVos =nursingProjectMapper.gerByPage(name,stauts);
        PageResponse<NursingProjectVo> nursingProjectVoPageResponse = PageResponse.of(nursingProjectVos,NursingProjectVo.class);
        return nursingProjectVoPageResponse;
    }

    @Override
    public void addNursingProject(NursingProjectVo nursingProjectVo) {
        NursingProject nursingProject=new NursingProject();
        nursingProject=BeanUtil.toBean(nursingProjectVo,NursingProject.class);
        nursingProjectMapper.addNursingProject(nursingProject);
    }

    @Override
    public NursingProjectVo showById(Long id) {
        NursingProject nursingProject= nursingProjectMapper.showById(id);
        return BeanUtil.toBean(nursingProject,NursingProjectVo.class);
    }

    @Override
    public void updataNursingProject(NursingProjectVo nursingProjectVo) {
        NursingProject nursingProject=BeanUtil.toBean(nursingProjectVo,NursingProject.class);
        nursingProjectMapper.updataNursingProject(nursingProject);
    }

    @Override
    public void deleteNursingProject(Long id) {
        nursingProjectMapper.deleteNursingProject(id);
    }

    @Override
    public void updataStatus(Long id, Integer status) {
        nursingProjectMapper.updataStatus(id,status);
    }

    @Override
    public List<NursingProject> getAllProjects() {
        List<NursingProject> nursingProjects = nursingProjectMapper.getALL();
        return nursingProjects;
    }
}
